package org.rambadger.command.view;

import com.yammer.dropwizard.auth.Auth;
import com.yammer.dropwizard.views.View;
import org.rambadger.command.auth.AuthUser;

import java.util.ArrayList;
import java.util.List;

public class UsersView extends View {
    public List<UserView> users;

    String title = ": Users";
    boolean area_users = true;
    boolean hasAdmin = false;
    //pagination variables
    boolean pagi,pagi_front,pagi_back = false;
    int pagi_less,pagi_great,pagi_limit,pagi_end;
    ArrayList<pagi> pagination;

    public UsersView(@Auth(required = false) AuthUser user, List<UserView> users){
        super("/usersList.mustache");
        this.users = users;
        this.hasAdmin = user.hasAdmin();
    }

    public UsersView(@Auth(required = false) AuthUser user, List<UserView> users, int pagesTotal, int usersPerPage, int currentPage){
        super("/usersList.mustache");
        this.users = users;
        this.hasAdmin = user.hasAdmin();
        this.pagi = true;
        if (currentPage == 1)
            this.pagi_front = true;
        if (currentPage == pagesTotal)
            this.pagi_back = true;
        pagination = new ArrayList<>();
        for (int i=1;i<=pagesTotal;i++){
             if (i == currentPage)
                 this.pagination.add(new pagi(i, false));
             else
                 this.pagination.add(new pagi(i,true));
         }
        this.pagi_less = currentPage - 1;
        this.pagi_great = currentPage + 1;
        this.pagi_limit = usersPerPage;
        this.pagi_end = pagesTotal;
    }
}

class pagi {
    int page;
    boolean active;

    public pagi(int page, boolean active) {
        this.page = page;
        this.active = active;
    }
}
